package cn.spike.rockcc.web.controller;

import cn.spike.rockcc.dto.AlipayNotifyDto;
import cn.spike.rockcc.dto.PayParamDto;
import cn.spike.rockcc.result.JSONResult;
import cn.spike.rockcc.service.IPayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * @author:spike
 * @create:2023-03-22 18:07
 */
@Controller
@RequestMapping("/pay")
public class PayController {

    @Autowired
    private IPayService payService;

    /**
     * 第三方退款接口
     */
    @PostMapping("/drawback")
    public JSONResult drawback(@RequestBody String orderNo){
        payService.drawback(orderNo);
        return JSONResult.success();
    }

    /**
     * 发起第三方支付申请
     * @param payParamDto
     * @return formUrl - 支付的form表单字符串
     */
    @PostMapping("/apply")
    @ResponseBody
    public JSONResult apply(@RequestBody PayParamDto payParamDto){
        String formUrl = payService.apply(payParamDto);
        return JSONResult.success(formUrl);
    }


    @RequestMapping("/alipayNotify")
    @ResponseBody
    public String aliPayNotify(AlipayNotifyDto alipayNotifyDto){
       String reslut = payService.aliPayNotify(alipayNotifyDto);
       return reslut;
    }

    @RequestMapping("/alipayReturn")
    public String aliPayReturn(){
     return "redirect:http://127.0.0.1:6002/pay.success.html";
    }

}
